package weixinkeji.dev.power.center.h;

import MyUI.ligerUI.service.LigeruiService;
import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
import java.util.List;
import sys.wx.ann.hm.H;
import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.GL;
import sys.wx.c.ATR;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.power.center.bean.SysUR;
import weixinkeji.dev.power.role.bean.SysRole;

/**
 *
 * @author IK
 */
@H("weixinkeji/dev/power/center/sysur/manager/s")
@GL
public class SysURSManager {

    ATR a;                  //ATR是必须要的。它封装了web请求的相关信息

    public SysURSManager(ATR obj) {     //这个有参构造函数，也是必须的。它进行附值
        this.a = obj;
    }

    /**
     * 查询出用户所拥有的角色。
     *
     * @return
     */
    @M("/userRole1N")//weixinkeji/dev/power/center/sysur/manager/s/userRole1N.imy
    public String ur1N() {
        a.printOne(JSON.toJSONString(getURByUserID()));
        return null;
    }

    @M("/userRole1NLigerui")//weixinkeji/dev/power/center/sysur/manager/s/userRole1N.imy
    public String ur1NLigerui() {
//        System.out.println(LigeruiService.getGRID(getURByUserID()));
        a.printOne(LigeruiService.getGRID_1_2(getURByUserID(), 1));
        return null;
    }

    private List<SysRole> getURByUserID() {
        List<SysUR> sv = Dao.selectVast(SysUR.class, Where.putThenGet(Where.TJ_IGNORE_EMPTY_NULL, SysUR.class, "", "user_id", "=", a.request.getParameter("uID")));
        StringBuilder sb = new StringBuilder();
        for (SysUR obj : sv) {
            sb.append(",'").append(obj.getRole_id()).append("'");
        }
        return sb.length() == 0 ? new ArrayList<>() : Dao.selectVast(SysRole.class, Where.putIN(Where.TJ_IGNORE_EMPTY_NULL, SysRole.class, "", "role_id", sb.substring(1)));
    }
}
